home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / xlib / intro.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  2KB  |  77 lines

  1. /*
  2.  * Copyright (c) 1993-94, Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  21.  */
  22. #include <GL/glx.h>
  23. #include <GL/gl.h>
  24. #include <unistd.h>
  25.  
  26.  
  27. static int attributeList[] = { GLX_RGBA, None };
  28.  
  29. static Bool WaitForNotify(Display *d, XEvent *e, char *arg) {
  30.     return (e->type == MapNotify) && (e->xmap.window ==    (Window)arg);
  31. }
  32.  
  33. int main(int argc, char    **argv)    {
  34.     Display *dpy;
  35.     XVisualInfo    *vi;
  36.     Colormap cmap;
  37.     XSetWindowAttributes swa;
  38.     Window win;
  39.     GLXContext cx;
  40.     XEvent event;
  41.  
  42.     /* get a connection    */
  43.     dpy    = XOpenDisplay(0);
  44.  
  45.     /* get an appropriate visual */
  46.     vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
  47.  
  48.     /* create a    GLX context */
  49.     cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
  50.  
  51.     /* create a    colormap */
  52.     cmap = XCreateColormap(dpy,    RootWindow(dpy,    vi->screen),
  53.                vi->visual, AllocNone);
  54.  
  55.     /* create a    window */
  56.     swa.colormap = cmap;
  57.     swa.border_pixel = 0;
  58.     swa.event_mask = StructureNotifyMask;
  59.     win    = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0,    100, 100,
  60.             0, vi->depth, InputOutput, vi->visual,
  61.             CWBorderPixel|CWColormap|CWEventMask, &swa);
  62.     XMapWindow(dpy, win);
  63.     XIfEvent(dpy, &event, WaitForNotify, (char*)win);
  64.  
  65.     /* connect the context to the window */
  66.     glXMakeCurrent(dpy,    win, cx);
  67.  
  68.     /* clear the buffer    */
  69.     glClearColor(1,1,0,1);
  70.     glClear(GL_COLOR_BUFFER_BIT);
  71.     glFlush();
  72.  
  73.     /* wait a while */
  74.     sleep(7);
  75. }
  76.  
  77.